<?php
    class WZ_SessionObject
    {
        public function __call($method, $args)
        {
            $methodCalled = substr($method, 0, 3);
            if ($methodCalled == 'get') {
                $uncamelizeMethod = \WZ_Inflector::uncamelize(lcfirst(substr($method, 3)));
                $var = strtolower($uncamelizeMethod);
                if (isset($this->$var)) {
                    return $this->$var;
                }
                return null;
            } elseif ($methodCalled == 'set') {
                $uncamelizeMethod = \WZ_Inflector::uncamelize(lcfirst(substr($method, 3)));
                $var = strtolower($uncamelizeMethod);
                $this->$var = $args[0];
            }
        }
        
        public function save()
        {
            $namespace = $this->getNamespace();
            $vars = get_object_vars($this);
            foreach ($vars as $key => $value) {
                $_SESSION[$namespace][$key] = $value;
            }
        }
        
        public function delete()
        {
            $namespace = $this->getNamespace();
            $_SESSION[$namespace] = array();
            return \WZ_Session::getInstance($namespace);
        }
    }